import React, { Component } from "react";
//引入组件
import Header from "../Header/Header";
//引入react-redux包
import { connect } from "react-redux";
//引入store
import { add_address_action } from "../../store/store";
class Add_address extends Component {
    constructor() {
        super();
        this.state = {
            addr: "",
            name: "",
            phone: ""
        };
    }
    render() {
        return (
            <div className="add_address">
                <Header title="新增收货地址"></Header>
                <div>
                    收货地址：
                    <input
                        type="text"
                        onChange={e => {
                            this.setState({
                                addr: e.target.value
                            });
                        }}
                    />
                </div>
                <div>
                    联系人：
                    <input
                        type="text"
                        onChange={e => {
                            this.setState({
                                name: e.target.value
                            });
                        }}
                    />
                </div>
                <div>
                    手机号：
                    <input
                        type="text"
                        onChange={e => {
                            this.setState({
                                phone: e.target.value
                            });
                        }}
                    />
                </div>
                <div
                    className="btn"
                    onClick={() => {
                        this.props.add(this.state);
                        this.props.history.push("/address");
                    }}
                >
                    保存地址
                </div>
            </div>
        );
    }
}
export default connect(
    state => {
        return {};
    },
    dispatch => {
        return {
            add(address) {
                dispatch(add_address_action(address));
            }
        };
    }
)(Add_address);
